﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ANN.FeedForward {
    public class Neuron : INeuron {
        public Neuron(int inputs, ANN.Math.IActivationFunction function) {
            InputCount = inputs;
            Inputs = new float[InputCount];
            Weights = new float[inputs];
            Function = function;
        }

        public override float Calculate(float[] input) {
            // If the number of inputs given does not match the number of inputs we expect, something is wrong!
            if (input.Length != InputCount) {
                throw new ArgumentException();
            }

            // Sum up all the inputs multiplied by their respective weights
            for (int i = 0; i < input.Length; i++) {
                Inputs[i] = input[i];
                Sum += Weights[i] * input[i];
            }

            // Insert the Sum value into the activation function and return the result
            return (Output = Function.Output(Sum));
        }
    }
}
